package cn.com.headfree.base.common;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.sgcc.isc.ualogin.client.vo.IscSSOUserBean;

import io.netty.util.internal.StringUtil;
@Component
public class UserLog {
	private static final Logger logger = Logger.getLogger(UserLog.class);
	
	private static String zuulRecordSysId;
	private static String zuulRecordSysName;
	
	@Value("${zuulRecord.sysId}")
	public void setZuulRecordSysId(String zuulRecordSysId) {
		UserLog.zuulRecordSysId = zuulRecordSysId;
	}
	@Value("${zuulRecord.sysName}")
	public void setZuulRecordSysName(String zuulRecordSysName) {
		UserLog.zuulRecordSysName = zuulRecordSysName;
	}

	public static void log(String ip,String userStr) {
		String loginTime = null;
		IscSSOUserBean user = JSONObject.parseObject(userStr,IscSSOUserBean.class);
		if(user.getLoginTime()!=null){
			loginTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(Long.valueOf(user.getLoginTime())));
		}
		logger.info(user.getIscUserId() + "\t" + user.getIscAdCode() + "\t" + user.getIscUserSourceId() + "\t" + ip + "\t"
				+ loginTime + "\t"+zuulRecordSysId+"\t"+zuulRecordSysName+ "\t"+user.getBaseOrgId()+"\t"+ (StringUtil.isNullOrEmpty(user.getBaseOrgName())?"null":user.getBaseOrgName()));

	}

}
